#include "stdafx.h"

CPanicButtonModule _AtlModule;

#if _DEBUG
static void _DllProcessAttach( void );
static void _DllProcessDetach( void );
static void _DllThreadAttach( void );
static void _DllThreadDetach( void );
#endif

extern "C" BOOL WINAPI DllMain( HINSTANCE /*hInstance*/, DWORD dwReason, LPVOID lpReserved ) {
#if _DEBUG
	switch ( dwReason ) {
		case DLL_PROCESS_ATTACH:
			_DllProcessAttach( );
			break;

		case DLL_PROCESS_DETACH:
			_DllProcessDetach( );
			break;

		case DLL_THREAD_ATTACH:
			_DllThreadAttach( );
			break;

		case DLL_THREAD_DETACH:
			_DllThreadDetach( );
			break;

		default:
			break;
	}
#endif

	return _AtlModule.DllMain( dwReason, lpReserved );
}

#if _DEBUG
static void _DllProcessAttach( void ) {
	_CrtSetReportMode( _CRT_WARN,   _CRTDBG_MODE_DEBUG );
	_CrtSetReportMode( _CRT_ERROR,  _CRTDBG_MODE_DEBUG );
	_CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_DEBUG );

	_CrtSetDbgFlag( _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG ) | _CRTDBG_ALLOC_MEM_DF | _CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_DELAY_FREE_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
}

static void _DllProcessDetach( void ) {
	_ASSERTE( _CrtCheckMemory( ) );
}

static void _DllThreadAttach( void ) {
}

static void _DllThreadDetach( void ) {
	_ASSERTE( _CrtCheckMemory( ) );
}
#endif
